package jianzhiOfferII;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//剑指 Offer II 015. 字符串中的所有变位词
public class Num015_findAnagrams {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> list = new ArrayList<>();
        int []arrs = new int[26];
        int []arrp = new int[26];
        int m = s.length() , n = p.length();
        for (int i = 0; i < n; i++) {
            arrp[p.charAt(i) - 'a']++;
        }
        for (int l = 0 , r = 0; r < m; r++) {
            arrs[s.charAt(r) - 'a']++;
            if (r - l + 1 > n){
                arrs[s.charAt(l++) - 'a']--;
            }
            if (check(arrp , arrs)){
                list.add(l);
            }

        }
        return list;

        
        

    }
    public boolean check(int []a1 , int []a2){
        return Arrays.equals(a1 , a2);
    }
}
